package com.hzy.wechat.feign;

import cn.hutool.json.JSONObject;
import com.hzy.wechat.annotation.FeignCache;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * Copyright (C), 2018-2023
 * FileName: WxAppletFeignService
 * Description: WxAppletFeignService
 * Author:   zengxin(zengxin@kbostar.com)
 * Date:     2023/4/23 19:15
 */
@FeignClient(name = "wxAppletFeignService", url = "https://api.weixin.qq.com")
public interface WxAppletFeign {

    /**
     * description: 获取微信网页授权tokenaccess_token
     *  首先请注意，这里通过code换取的是一个特殊的网页授权access_token,与基础支持中的access_token（该access_token用于调用其他接口）不同。
     *  公众号可通过下述接口来获取网页授权access_token。
     *  如果网页授权的作用域为snsapi_base，则本步骤中获取到网页授权access_token的同时，也获取到了openid，snsapi_base式的网页授权流程即到此为止。
     *  尤其注意：由于公众号的secret和获取到的access_token安全级别都非常高，必须只保存在服务器，不允许传给客户端。
     *  后续刷新access_token、通过access_token获取用户信息等步骤，也必须从服务器发起。
     * @param appid     公众号的唯一标识
     * @param secret    公众号的appsecret
     * @param code
     * @return:java.lang.String
     * @since: 1.0.0
     * @Author:zengxin
     * @Date: 2023/4/4 15:59
     */
    @GetMapping(value = "/sns/oauth2/access_token?grant_type=authorization_code")
    @FeignCache(expiresIn = 7200)
    String getWxOpenId(@RequestParam(name = "appid", required = false) String appid, @RequestParam(name = "secret", required = false) String secret, @RequestParam(name = "code", required = false) String code);

    @GetMapping(value = "/cgi-bin/token?grant_type=client_credential")
    @FeignCache(expiresIn = 7200)
    String getAccessToken(@RequestParam(name = "appid", required = false)String appId, @RequestParam(name = "secret", required = false) String secret);

    @GetMapping(value = "/cgi-bin/ticket/getticket")
    @FeignCache(expiresIn = 7200)
    String getTicket(@RequestParam(name = "access_token", required = false) String accessToken, @RequestParam(name = "type", defaultValue = "jsapi") String type);

    @GetMapping(value = "/sns/userinfo?lang=zh_CN")
    @FeignCache(expiresIn = 7200)
    String getUserinfo(@RequestParam(name = "access_token", required = false) String access_token, @RequestParam(name = "openid", required = false) String openid);

    @GetMapping(value = "/sns/jscode2session?grant_type=authorization_code")
    @FeignCache(expiresIn = 7200)
    String jscode2session(@RequestParam(name = "appid", required = false) String appid, @RequestParam(name = "secret", required = false) String secret, @RequestParam(name = "js_code", required = false) String code);

    @GetMapping(value = "/wxa/business/getuserphonenumber")
    @FeignCache(expiresIn = 7200)
    String getuserphonenumber(@RequestParam(name = "access_token", required = false) String access_token);


//    @RequestMapping(value = "/wxa/getwxacodeunlimit?access_token={accessToken}", method = RequestMethod.POST, consumes = "application/json")

//    @PostMapping(value = "/wxa/getwxacodeunlimit" , consumes = "application/json")
//    byte[] getUnlimited(@RequestParam(name = "access_token", required = false) String access_token, JSONObject cmd);

    @RequestMapping(value = "/wxa/getwxacodeunlimit?access_token={accessToken}", method = RequestMethod.POST, consumes = "application/json")
    byte[] getUnlimited(@PathVariable("accessToken") String accessToken, JSONObject cmd);

}
